/*
 * @Author: Jiraiya
 * @Date: 2020-05-12 16:16:05
 * @LastEditors: Jiraiya
 * @LastEditTime: 2020-05-12 16:24:01
 * @Description: 
 */


// https://zh-hans.reactjs.org/docs/context.html#reactcreatecontext
// 可以用组件组合传递 直接将组件直接传导下去

export function createContext(
    defaultValue,
    calculateChangedBits
){
    if (calculateChangedBits === undefined) {
        calculateChangedBits = null;
    }

    const context = {
        $$typeof: REACT_CONTEXT_TYPE,
        _calculateChangedBits: calculateChangedBits,
        // As a workaround to support multiple concurrent renderers, we categorize
        // some renderers as primary and others as secondary. We only expect
        // there to be two concurrent renderers at most: React Native (primary) and
        // Fabric (secondary); React DOM (primary) and React ART (secondary).
        // Secondary renderers store their context values on separate fields.
        _currentValue: defaultValue,
        _currentValue2: defaultValue,
        // These are circular
        Provider: null,
        Consumer: null,
    };

    context.Provider = {
        $$typeof: REACT_PROVIDER_TYPE,
        _context: context,
    };
    context.Consumer = context;
    
    return context;
}